package com.oreilly.android.taskmanager.views;

import java.util.ArrayList;
import java.util.List;

import android.graphics.drawable.Drawable;
import android.location.Address;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;

public class AddressOverlay extends ItemizedOverlay<AddressOverlayItem> {

	private List<Address> addresses;

	private Address selectedAddress;

	public AddressOverlay(Drawable drawable) {
		super(boundCenterBottom(drawable));
		this.addresses = new ArrayList<Address>();
		populate();
	}

	@Override
	protected AddressOverlayItem createItem(int i) {
		Address add = addresses.get(i);

		int latitude = (int) (add.getLatitude() * 1E6);
		int longitude = (int) (add.getLongitude() * 1E6);
		// String title =
		GeoPoint point = new GeoPoint(latitude, longitude);

		AddressOverlayItem item = new AddressOverlayItem(point, add.toString(),
				"test snippet");

		return item;
	}

	@Override
	public int size() {
		return addresses.size();
	}

	@Override
	protected boolean onTap(int index) {
		super.onTap(index);

		selectedAddress = addresses.get(index);

		return true;
	}

	public List<Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(List<Address> add) {
		this.addresses = add;
		populate();
	}

	public Address getSelectedAddress() {
		return selectedAddress;
	}

	public void setSelectedAddress(Address selectedAddress) {
		this.selectedAddress = selectedAddress;
	}
}
